package JavaStructure.Array;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;


public class Test {

    public static void main(String[] args) {

    }

    public List<List<Integer>> generate(int numRows) {

        List<List<Integer>> ret = new ArrayList<>();
        //处理第一行
        List<Integer> list = new ArrayList<>();
        list.add(1);

        ret.add(list);

        for (int i = 1; i < numRows; i++) {
            //先处理每一行的第一个元素为1
            List<Integer> curRow = new ArrayList<>();
            curRow.add(1);
            //中间
            List<Integer> prePow = ret.get(i - 1);
            for (int j = 1; j < i; j++) {
                //[i][j] = [i-1][j] + [i-1][j-1];
                int val = prePow.get(j) + prePow.get(j - 1);
                curRow.add(val);
            }
            //处理最后一个
            curRow.add(1);

            ret.add(curRow);
        }

        return ret;
    }

    public static void main3(String[] args) {

        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
//        @ @ -11, 6 + 42, 39 @@;

        arrayList.add(3);
        arrayList.add(4);

        System.out.println(arrayList);

        for(
            int i = 0; i<arrayList.size();i++)

            {
                System.out.print(arrayList.get(i) + " ");
            }
        System.out.println();

        for(
            Integer x :arrayList)

            {
                System.out.print(x + " ");
            }
        System.out.println();

        System.out.println("=====================");

            Iterator<Integer> it = arrayList.iterator();
        while(it.hasNext())

            {
                System.out.print(it.next() + " ");
            }
        System.out.println();
        System.out.println("==========ListIterator===========");

            ListIterator<Integer> lit = arrayList.listIterator(1);
        while(lit.hasNext())

            {
                System.out.print(lit.next() + " ");
            }
        System.out.println();
        System.out.println("==========ListIterator===========");

            ListIterator<Integer> lit2 = arrayList.listIterator(arrayList.size());
        while(lit2.hasPrevious())

            {
                System.out.print(lit2.previous() + " ");
            }
        System.out.println();

            List<Integer> list = new ArrayList<>();
        }

        public static void main2 (String[]args){
            ArrayList<Integer> arrayList = new ArrayList<>();
            arrayList.add(1);
            arrayList.add(2);
            arrayList.add(3);
            arrayList.add(4);
            arrayList.add(5);
            System.out.println(arrayList);

            List<Integer> list = arrayList.subList(1, 4);//[1,4)
            System.out.println(list);
            System.out.println("===================");

            list.set(0, 22);
            System.out.println(list);
            System.out.println(arrayList);


       /* arrayList.add(0,99);
        System.out.println(arrayList);

        arrayList.remove(new Integer(99));
        System.out.println(arrayList);

        arrayList.clear();
        System.out.println(arrayList);*/


       /* ArrayList<Integer> arrayList2 = new ArrayList<>(arrayList);
        arrayList2.add(9);
        System.out.println(arrayList2);
        */


        }
//        public static void main1 (String[]args){
//            MyArrayList list = new MyArrayList();
//            list.add(1);
//            list.add(2);
//            list.add(3);
//            list.add(4);
//            list.add(5);
//            list.add(99);
//            list.display();
//
//            list.remove(199);
//            list.display();
//
//   /*     try {
//            list.add(0,199);
//        }catch (PosOutOfBoundsException e) {
//          *//*  pos = 9;
//            list.add(pos,199);*//*
//            e.printStackTrace();
//        }
//
//        list.display();
//        list.set(6,88);
//        list.display();*/
//
//        /*System.out.println(list.contains(99));
//        System.out.println(list.indexOf(99));*/
//
//        }
    }

